<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    window.onload = () => {
      const oProgress = document.getElementsByClassName('progress')[0]
      let counter = 0;
      const timer = setInterval(() => {
        if(counter<10){
          counter += 1
          console.log(counter);
        oProgress.style.width = counter*10+'%'
        }else{
          console.log('定时器结束!');
          clearInterval(timer)
          // location.reload()   
        }
        
      }, 20)
    }
  </script>
   <style>
    *{
      margin: 0;
      padding: 0;
    }
    .box{
      width: 100px;
      height: 20px;
      background-color: cyan;
    }
    .progress{
      height: 100%;
      width: 0;
      background-color: black;
    }
  </style>
  <div class="box">
    <div class="progress" ></div>
  </div>
</body>
</html>